package leetcom.com249;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Ex5809 {
    public int countPalindromicSubsequence(String s) {

        int res = 0;
        Set<Character> bigSet = new HashSet<>();
        for (int i = 0; i <= s.length()-3; i++) {
            char ch = s.charAt(i);
            if(!bigSet.add(ch)){
                continue;
            }
            Set<Character> set = new HashSet<>();
            int j = s.length()-1;
            while(i+2<=j&&ch!=s.charAt(j)){
                j--;
            }
            if(ch==s.charAt(j)){
                for (int k = i+1; k < j; k++) {
                    set.add(s.charAt(k));
                }
                res+=set.size();
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Ex5809 ex5809 = new Ex5809();
        ex5809.countPalindromicSubsequence("aabca");
    }
}
